package com.shopping.shoppingdemo.utils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

public class TimeUtils {
    public static Instant parseToInstant(String s) {
        try {
            return Instant.parse(s);
        } catch (Exception ex) {
            try {
                LocalDateTime ldt = LocalDateTime.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));
                return ldt.toInstant(ZoneOffset.UTC);
            } catch (Exception ex2) {
                return Instant.ofEpochMilli(Long.parseLong(s));
            }
        }
    }
}